<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>

      <el-form-item style="float: right;" label="" v-if="isAuth('hotel:hotelseller:list')">
        <selectSeller @change="selectSellerChange"></selectSeller>
      </el-form-item>

      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('hotel:thotelfloorscheme:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('hotel:thotelfloorscheme:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="jmname"
        header-align="center"
        align="center"
        label="简码">
      </el-table-column>
      <el-table-column
        prop="no"
        header-align="center"
        align="center"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="房价方案">
      </el-table-column>

      <el-table-column
        prop="typetext"
        header-align="center"
        align="center"
        label="客人来源">
      </el-table-column>
      <el-table-column
        prop="creatTime"
        header-align="center"
        align="center"
        label="操作时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
           <el-button type="text" size="small" @click="showxq(scope.row)">详情</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>




    <el-dialog  title="每日房价"
    class="mrfj-dialog"
    :close-on-click-modal="false"
    :visible.sync="showckfj" append-to-body>
         <el-date-picker width="33%"
          style="transform: translateY(45px);margin-left: 14%;width: 36%;"
            v-model="value1"
            clearable
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
          <el-input type="number" placeholder="请输入房价" clearable v-model="demomoney" style="width: 16%;margin-left: 1%;margin-right: 1%;transform: translateY(45px);"></el-input>
          <el-button type="primary" size="small" style="transform: translateY(45px);" @click="savedata" >确定</el-button>
    <el-calendar v-model="value">
      <!-- 这里使用的是 2.5 slot 语法，对于新项目请使用 2.6 slot 语法-->

      <template
        slot="dateCell"
        slot-scope="{date, data}">
        <p :class="data.isSelected ? 'is-selected' : ''" @click="getthotelFloorfj(demo.id,data.day)">
          {{ data.day.split('-').slice(1).join('-') }}
          {{ data.isSelected ? '✔️' : ''}}
           <div v-for="(item,i) in list" v-bind:key="item.data">
             <span  v-if="item.datas.split('-').slice(1).join('-')==data.day.split('-').slice(1).join('-')+' 00:00:00'">
               <el-tag @click="showtag(item)">{{item.money}}</el-tag>
             </span>
           </div>
        </p>


      </template>
    </el-calendar>
    </el-dialog>




    <el-dialog  title="修改房价"
    :close-on-click-modal="false"
    :visible.sync="showtagdialog" width="18%">
         <el-input v-model="money.money"></el-input>
         <span slot="footer" class="dialog-footer">
           <el-button @click="showtagdialog = false">取消</el-button>
           <el-button type="primary" @click="dataSubmit()">确定</el-button>
         </span>
    </el-dialog>

    <el-dialog  title="房间详情"
    :close-on-click-modal="false"
    :visible.sync="showxqlb">
      <el-table
      		  :data="foomdatalist"
      		  border=""
      		  v-loading="dataListLoadings"
      		  style="width: 100%;"

      		>
      		  <el-table-column prop="name" header-align="center" align="center" label="房间类型"></el-table-column>
      		  <el-table-column prop="price" header-align="center" align="center" label="门市价"></el-table-column>
      		  <el-table-column  header-align="center" align="center" label="执行房价">
              <template  slot-scope="scope">
                <el-input type="number" min="0"  v-model="scope.row.money" @change="updateByid(scope.row)"></el-input>
              </template>
            </el-table-column>
      		<el-table-column  header-align="center" align="center" label="早餐份数">
            <template  slot-scope="scope">
              <el-input type="number" min="0" v-model="scope.row.zcnumber" @change="updateByid(scope.row)"></el-input>
            </template>
          </el-table-column>
      		<el-table-column header-align="center" align="center" label="默认离店时间">
            <template  slot-scope="scope">
              <el-time-select
                v-model="scope.row.ldtime"
                :picker-options="{
                  start: '12:00',
                  step: '00:01',
                  end: '18:00'
                }"
                placeholder="选择时间" @change="updateByid(scope.row)">
              </el-time-select>
            </template>
          </el-table-column>
          <el-table-column  header-align="center" align="center" label="查看每日房价">
            <template  slot-scope="scope">
              <el-button type="primary" @click="ckfj(scope.row)">查看房价</el-button>
            </template>
          </el-table-column>
      </el-table>
    </el-dialog>





  </div>
</template>

<script>
  import AddOrUpdate from './thotelfloorscheme-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        value1:'',
        list:[],
        sellerIds:[],
        demomoney:'',
        value: new Date(),
        showckfj:false,
        foomdatalist:[],
        demo:{},
        showtagdialog:false,
        money:{},
        showxqlb:false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        ceshishow:false,
        dataListLoadings:false,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {

        selectSellerChange(val){
          console.log("接收值",val);
          this.sellerIds = val;
          this.getDataList();
        },
      savedata(){
        if(this.demomoney==''){
          this.$message({
            message: '请输入正确房价',
            type: 'error',
          })
         return false;
        }
        if(this.value1==''){
          this.$message({
            message: '请输入正确时间',
            type: 'error',
          })
         return false;
        }
        var starttime=this.getdatastring(this.value1[0]);
        var endtime=this.getdatastring(this.value1[1]);

        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorschemeroomjl/saveArray`),
          method: 'post',
          data: this.$http.adornParams({
            'starttime': starttime,
            'endtime': endtime,
            'money': this.demomoney,
            'schemeRoomId':this.demo.id
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                var dateString=this.getdatastring(new Date());
               this.getthotelFloorfj(this.demo.id,dateString);
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })


      },
      clears(){
        this.value1='';
        this.demomoney='';
      },
      dataSubmit(){
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorschemeroomjl/save`),
          method: 'post',
          data: this.money
        }).then(({data}) => {
          if (data && data.code === 0) {
             this.showtagdialog=false;
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      showtag(row){
        this.money=row;
        this.showtagdialog=true;
      },

      showxq(row){

       this.getzbDatalist(row);
      },
      getdatastring(data){
        var year =data.getFullYear();//获取完整的年份(4位,1970-????)
         var month = data.getMonth() + 1;//获取当前月份(0-11,0代表1月)
         var day = data.getDate();//获取当前日(1-31)
         if (month < 10) {
          month ="0" + month;
          }
         if (day < 10) {
          day ="0" + day;
          }
         var dateString =year +"-" + month + "-" + day;
         return dateString;
      },
      ckfj(row){
         this.demo=row;
          var dateString=this.getdatastring(new Date());
          this.value=new Date();
         this.getthotelFloorfj(row.id,dateString);

      },
      getthotelFloorfj(id,dateString){
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorschemeroomjl/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': 1,
            'limit':999,
            'id':id,
            'data':dateString
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.list = data.page.list
              this.showckfj=true;
          } else {
            this.list = []
          }
        })
      },

      getzbDatalist(item){
        this.dataListLoadings = true
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorschemeroom/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': 1,
            'limit':999,
            'schemeId':item.id
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.foomdatalist = data.page.list
             this.showxqlb=true;
          } else {
            this.foomdatalist = []
          }
          this.dataListLoadings = false
        })
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorscheme/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            sellerIds:this.sellerIds.join(",")
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      updateByid(row){
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorschemeroom/updateByid`),
          method: 'post',
          data: row
        }).then(({data}) => {
          if (data && data.code === 0) {
            // this.$message({
            //   message: '操作成功',
            //   type: 'success',
            //   duration: 1500,
            //   onClose: () => {
            //     this.visible = false
            //     this.$emit('refreshDataList')
            //   }
            // })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelfloorscheme/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style lang="scss">
   .is-selected {
      color: #1989FA;
      }

      .el-backtop, .el-calendar-table td.is-today{
        color: #606266 !important;
      }
      .el-calendar__title{
        font-size: 18px;
      }
  .mrfj-dialog {
    /deep/ .el-range-separator {
      width: 7%;
    }
  }
  @media (max-width: 1500px) {
    .mrfj-dialog {
      .el-dialog {
        width: 80%;
      }
    }
  }
</style>
